﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TreeCommon.ascx.cs"
    Inherits="Sagacity.NC.Web.Form.WebTreeControl" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>

<script language="javascript" type="text/javascript">
        var selectedNodeId = 0;        
        var selectedNode=null;
        var selectedChilds = false;//是否选中子节点
        var selectedNodesId = null;//选中节点和子节点Id(在selectedChilds为true的情况下，包括子节点在内的所有节点的编号)
       
        //实现ajaxc的绑定，点击某个节点才去绑定它下面的子内容
           function nodeLoad(node) {
            Coolite.AjaxMethods.<%=this.ClientID %>.InitTree(node.id, {
                success: function(result) {
                    var data = eval("(" + result + ")");
                    node.loadNodes(data);
                },

                failure: function(errorMsg) {
                   Ext.Msg.alert('提示', '正在加载数据，请稍候...');
                }
            });
        }
        
       //重新绑定树内容相当于刷新重置
       var RefreshTree = function(){
        Coolite.AjaxMethods.<%=this.ClientID %>.RefreshTree({
                success: function(result) {
                   var data = eval("(" + result + ")");                  
                   <%=TreePanel.ClientID %>.root.reload();
                },

                failure: function(errorMsg) {
                    Ext.Msg.alert('提示', '正在加载数据，请稍候...');
                }
            });
        } 
        
         //这是查询搜索方法
       function nodeLoadSearch() {
       var seach = <%=txtFieldSearch.ClientID %>.getValue();
       if(seach == null || seach=="")
       {
            RefreshTree();
       }else{   
           //这是调用后台[AjaxMethod]方法
           Coolite.AjaxMethods.<%=this.ClientID %>.LodeSeach({
                success: function(result) {
                    //var data = eval("(" + result + ")");
                  <%=TreePanel.ClientID %>.root.reload();
                },

                failure: function(errorMsg) {
                            Ext.Msg.alert('提示', '正在加载数据，请稍候...');
                },
                timeout:3600000
            });}
       }
       
        function nodeLoadSearch(express) {
           //这是调用后台[AjaxMethod]方法
           Coolite.AjaxMethods.<%=this.ClientID %>.LodeSeachByExpress(express,{
                success: function(result) {
                    //var data = eval("(" + result + ")");
                  <%=TreePanel.ClientID %>.root.reload();
                },

                failure: function(errorMsg) {
                            Ext.Msg.alert('提示', '正在加载数据，请稍候...');
                },
                timeout:3600000
            });
       }
       
       
       //这是把点击树中某列时通过js绑定到Panel中
       function showForm(node) {
            selectedNode = node;
            
            if(!selectedChilds){
                selectedNodeId = node.id;
                evalShowFunction();
            }else{
                selectedNodesId = node.id+","
                Coolite.AjaxMethods.<%=this.ClientID %>.GetSelNodeChildsId(node.id,{
                    success:function(result){                        
                        selectedNodesId += result;
                        selectedNodesId = selectedNodesId.substring(0,selectedNodesId.length - 1);
                        evalShowFunction();
                    },
                    failure:function(msg){
                        Ext.Msg.alert("错误",msg);
                    }
                });
            }
       }
       
       function evalShowFunction(){
            if(typeof showFunctionName != 'undefined'){	  
                eval(showFunctionName);
            }
       }
       
       //获取所有选中节点
       function getCheckedNodes(node) {
            selectedNodesId = "";
            var nodeArray = node.childNodes;
            for (var i = 0; i < nodeArray.length; i++){  
                selectedNodesId += nodeArray[i].id + ",";
                if (nodeArray[i].hasChildNodes()){
                    getCheckedNode(nodeArray[i]);
                }
            }
        }


        function onKeyDownDefault() 
        { 
             if (window.event.keyCode == 13 && window.event.ctrlKey == false && window.event.altKey == false){ 
                 if (window.event.srcElement.type != "button") 
                     window.event.keyCode = 9; 
             } 
             else{ 
                 return true; 
             } 
             nodeLoadSearch();
             <%=txtFieldSearch.ClientID%>.focus();
        } 
</script>

<!--配置信息-->
<ext:Hidden ID="hidResourceId" runat="server" Text="0" />
<ext:Hidden ID="hidUrl" runat="server" />

<ext:BorderLayout ID="BorderLayout" runat="server">
<Center>
<ext:TreePanel ID="TreePanel" Border="false" AutoScroll="true" 
 runat="server" Header="false" Title="tree ">
    <TopBar>
        <ext:Toolbar ID="toolBarPanel" Visible="true" runat="server">
            <Items>
                <ext:TextField ID="txtFieldSearch" AutoPostBack="false" Width="100" EnableKeyEvents="true" runat="server">
                    <Listeners>
                        <KeyDown Handler="javascript:onKeyDownDefault()" />
                    </Listeners>
                </ext:TextField>
                <ext:Button ID="btnSearch" runat="server" Visible="true" Cls="txtKM" Text="搜 索">
                    <Listeners>
                        <Click Handler="javascript:nodeLoadSearch()" />
                    </Listeners>
                </ext:Button>
                <ext:ToolbarButton ID="ToolbarButton1" runat="server" Icon="ChartOrganisation">
                    <Listeners>
                        <Click Handler="#{TreePanel}.expandAll();" />
                    </Listeners>
                    <ToolTips>
                        <ext:ToolTip ID="ToolTip1" IDMode="Ignore" runat="server" Html="展开" />
                    </ToolTips>
                </ext:ToolbarButton>
                <ext:ToolbarButton ID="ToolbarButton2" runat="server"  Icon="ChartOrganisationAdd" >
                    <Listeners>
                        <Click Handler="#{TreePanel}.collapseAll();" />
                    </Listeners>
                    <ToolTips>
                        <ext:ToolTip ID="ToolTip2" IDMode="Ignore" runat="server" Html="折叠" />
                    </ToolTips>
                </ext:ToolbarButton>
            </Items>
        </ext:Toolbar>
    </TopBar>
    <Root>
        <ext:AsyncTreeNode NodeID="0">
        </ext:AsyncTreeNode>
    </Root>
    <Listeners>
        <BeforeLoad Fn="nodeLoad" />
    </Listeners>
</ext:TreePanel>
</Center>
</ext:BorderLayout>